/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Kampania_Kontroler.java
 *
 * Created on 2010-06-03, 16:58:03
 */

package adbus;

import adbus.models.*;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;

/**
 *klasa odpowiedzialna z wyswietlanie okna dodania klienta
 * i obsluge zdarzen z nim zwiazanych
 * @author rafal
 */
public class Klient_Kontroler extends javax.swing.JDialog {
    private Klient client = new Klient();
    private KlientTable clientsTable = null;

    /** Creates new form Kampania_Kontroler */
    public Klient_Kontroler(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
/**dwuargumentowy konstruktor klasy Klient_Kontener*/
    public Klient_Kontroler(JFrame mainFrame, KlientTable kTable) {
        super(mainFrame,true);
        initComponents();
        clientsTable = kTable;
    }
    /**trzyargumentowy konstruktor klasy Klient_Kontener*/
    public Klient_Kontroler(JFrame mainFrame, KlientTable kTable, Klient klient) {
        super(mainFrame,true);
        client = klient;
        clientsTable = kTable;
        initComponents();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        clientNameLabel = new javax.swing.JLabel();
        clientName = new javax.swing.JTextField();
        clientCityLabel = new javax.swing.JLabel();
        clientAddressLabel = new javax.swing.JLabel();
        clientNIPLabel = new javax.swing.JLabel();
        clientInformationLabel = new javax.swing.JLabel();
        clientPhoneLabel = new javax.swing.JLabel();
        clientMailLabel = new javax.swing.JLabel();
        clientAddress = new javax.swing.JTextField();
        clientNIP = new javax.swing.JTextField();
        clientMail = new javax.swing.JTextField();
        clientCity = new javax.swing.JTextField();
        clientPhone = new javax.swing.JTextField();
        clientInformation = new javax.swing.JTextField();
        clientNameLabel7 = new javax.swing.JLabel();
        clientCPNameLabel = new javax.swing.JLabel();
        clientCPSurnameLabel = new javax.swing.JLabel();
        clientCPPhoneLabel = new javax.swing.JLabel();
        clientCPMailLabel = new javax.swing.JLabel();
        clientCPName = new javax.swing.JTextField();
        clientCPMail = new javax.swing.JTextField();
        clientCPSurname = new javax.swing.JTextField();
        clientCPPhone = new javax.swing.JTextField();
        CancelButton = new javax.swing.JButton();
        OKButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adbus.AdBusApp.class).getContext().getResourceMap(Klient_Kontroler.class);
        clientNameLabel.setText(resourceMap.getString("clientNameLabel.text")); // NOI18N
        clientNameLabel.setName("clientNameLabel"); // NOI18N

        clientName.setText(client.nazwa);
        clientName.setName("clientName"); // NOI18N

        clientCityLabel.setText(resourceMap.getString("clientCityLabel.text")); // NOI18N
        clientCityLabel.setName("clientCityLabel"); // NOI18N

        clientAddressLabel.setText(resourceMap.getString("clientAddressLabel.text")); // NOI18N
        clientAddressLabel.setName("clientAddressLabel"); // NOI18N

        clientNIPLabel.setText(resourceMap.getString("clientNIPLabel.text")); // NOI18N
        clientNIPLabel.setName("clientNIPLabel"); // NOI18N

        clientInformationLabel.setText(resourceMap.getString("clientInformationLabel.text")); // NOI18N
        clientInformationLabel.setName("clientInformationLabel"); // NOI18N

        clientPhoneLabel.setText(resourceMap.getString("clientPhoneLabel.text")); // NOI18N
        clientPhoneLabel.setName("clientPhoneLabel"); // NOI18N

        clientMailLabel.setText(resourceMap.getString("clientMailLabel.text")); // NOI18N
        clientMailLabel.setName("clientMailLabel"); // NOI18N

        clientAddress.setText(client.adres);
        clientAddress.setName("clientAddress"); // NOI18N

        clientNIP.setText(client.nip);
        clientNIP.setName("clientNIP"); // NOI18N

        clientMail.setText(client.mail);
        clientMail.setName("clientMail"); // NOI18N

        clientCity.setText(client.miasto);
        clientCity.setName("clientCity"); // NOI18N

        clientPhone.setText(client.telefon);
        clientPhone.setName("clientPhone"); // NOI18N

        clientInformation.setText(client.uwagi);
        clientInformation.setName("clientInformation"); // NOI18N

        clientNameLabel7.setText(resourceMap.getString("clientNameLabel7.text")); // NOI18N
        clientNameLabel7.setName("clientNameLabel7"); // NOI18N

        clientCPNameLabel.setText(resourceMap.getString("clientCPNameLabel.text")); // NOI18N
        clientCPNameLabel.setName("clientCPNameLabel"); // NOI18N

        clientCPSurnameLabel.setText(resourceMap.getString("clientCPSurnameLabel.text")); // NOI18N
        clientCPSurnameLabel.setName("clientCPSurnameLabel"); // NOI18N

        clientCPPhoneLabel.setText(resourceMap.getString("clientCPPhoneLabel.text")); // NOI18N
        clientCPPhoneLabel.setName("clientCPPhoneLabel"); // NOI18N

        clientCPMailLabel.setText(resourceMap.getString("clientCPMailLabel.text")); // NOI18N
        clientCPMailLabel.setName("clientCPMailLabel"); // NOI18N

        clientCPName.setText(client.ok_imie);
        clientCPName.setName("clientCPName"); // NOI18N

        clientCPMail.setText(client.ok_mail);
        clientCPMail.setName("clientCPMail"); // NOI18N

        clientCPSurname.setText(client.ok_nazwisko);
        clientCPSurname.setName("clientCPSurname"); // NOI18N

        clientCPPhone.setText(client.ok_telefon);
        clientCPPhone.setName("clientCPPhone"); // NOI18N

        CancelButton.setText(resourceMap.getString("CancelButton.text")); // NOI18N
        CancelButton.setName("CancelButton"); // NOI18N
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        OKButton.setText(resourceMap.getString("OKButton.text")); // NOI18N
        OKButton.setName("OKButton"); // NOI18N
        OKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(clientNIPLabel)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(clientNameLabel)
                            .addComponent(clientAddressLabel)
                            .addComponent(clientCityLabel)
                            .addComponent(clientPhoneLabel)
                            .addComponent(clientMailLabel)
                            .addComponent(clientInformationLabel)
                            .addComponent(clientNameLabel7)
                            .addComponent(clientCPPhoneLabel)
                            .addComponent(clientCPMailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(clientNIP, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientName, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientCity, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientMail, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientInformation, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientCPName, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientCPSurname, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientCPPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(clientCPMail, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(CancelButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(OKButton))))
                    .addComponent(clientCPNameLabel)
                    .addComponent(clientCPSurnameLabel))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientNameLabel)
                    .addComponent(clientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientNIPLabel)
                    .addComponent(clientNIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientAddressLabel))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientCityLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientPhoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientMailLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientInformation, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientInformationLabel))
                .addGap(24, 24, 24)
                .addComponent(clientNameLabel7)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientCPNameLabel)
                    .addComponent(clientCPName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientCPSurnameLabel)
                    .addComponent(clientCPSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientCPPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientCPPhoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientCPMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientCPMailLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OKButton)
                    .addComponent(CancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**metoda odpowiedzialna za obsluge przycisku ok*/
    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
        // TODO add your handling code here:
        client.nazwa = clientName.getText();
        client.nip = clientNIP.getText();
        client.adres = clientAddress.getText();
        client.miasto = clientCity.getText();
        client.telefon = clientPhone.getText();
        client.ok_imie = clientCPName.getText();
        client.mail = clientMail.getText();
        client.ok_nazwisko = clientCPSurname.getText();
        client.ok_telefon = clientCPPhone.getText();
        client.ok_mail = clientCPMail.getText();
        client.uwagi = clientInformation.getText();
        client.zapisz();
        dispose();
        if(clientsTable!=null) {
            clientsTable.zaladuj();
        }
    }//GEN-LAST:event_OKButtonActionPerformed
/**metoda odpowiedzialna za obsluge przycisku anuluj*/
    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
        dispose();
    }//GEN-LAST:event_CancelButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Klient_Kontroler dialog = new Klient_Kontroler(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CancelButton;
    private javax.swing.JButton OKButton;
    private javax.swing.JTextField clientAddress;
    private javax.swing.JLabel clientAddressLabel;
    private javax.swing.JTextField clientCPMail;
    private javax.swing.JLabel clientCPMailLabel;
    private javax.swing.JTextField clientCPName;
    private javax.swing.JLabel clientCPNameLabel;
    private javax.swing.JTextField clientCPPhone;
    private javax.swing.JLabel clientCPPhoneLabel;
    private javax.swing.JTextField clientCPSurname;
    private javax.swing.JLabel clientCPSurnameLabel;
    private javax.swing.JTextField clientCity;
    private javax.swing.JLabel clientCityLabel;
    private javax.swing.JTextField clientInformation;
    private javax.swing.JLabel clientInformationLabel;
    private javax.swing.JTextField clientMail;
    private javax.swing.JLabel clientMailLabel;
    private javax.swing.JTextField clientNIP;
    private javax.swing.JLabel clientNIPLabel;
    private javax.swing.JTextField clientName;
    private javax.swing.JLabel clientNameLabel;
    private javax.swing.JLabel clientNameLabel7;
    private javax.swing.JTextField clientPhone;
    private javax.swing.JLabel clientPhoneLabel;
    // End of variables declaration//GEN-END:variables

   
}
